package servlet;

import pojo.Brand;
import service.BrandService;

import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.annotation.*;
import java.io.IOException;

@WebServlet(name = "ToUpdateServlet", value = "/toUpdate")
public class ToUpdateServlet extends HttpServlet {
    private BrandService brandService = new BrandService();
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        //1.接受一个id (待修改品牌)、
        String id = request.getParameter("id");
        Integer idd = Integer.valueOf(id);
        //2.调用service层的方法进行查询
        Brand brand = brandService.selectById(idd);
        //3.将查询结果保存到域中
        request.setAttribute("brand",brand);
        //4.转发到修改页面上，进行展示
        request.getRequestDispatcher("/updateBrand.jsp").forward(request,response);
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doGet(request, response);
    }
}
